#ifndef BODYWRAPPER_H
#define BODYWRAPPER_H

#include <vector>
#include <map>
#include <Box2D/Box2D.h>
#include <QPainter>
#include "worldsimulator.h"
#include "forcewrapper.h"

class BodyWrapper
{
public:
    BodyWrapper(b2World *world,
                b2Shape::Type shape_type,
                b2BodyType body_type,
                b2Vec2 pivot_center,
                float angle_in_radius = 0.f,
                float density = 0.f,
                float friction = 0.f)
        : curr_force_id(0),
          world(world),
          shape_type(shape_type),
          body_type(body_type),
          pivot_center(pivot_center),
          angle_in_radius(angle_in_radius),
          density(density),
          friction(friction),
          body(0)
    {}

    static bool pointInRegion(b2Vec2 point, int top, int left, int right, int bottom);
    b2Vec2 getPosition() { return body->GetPosition(); }
    float getAngle() { return body->GetAngle(); }
    b2Body *getBody() { return body; }
    int applyForce(ForceWrapper *force);
    void removeForce(int forceId);
    void applyImpulse(b2Vec2 impulse);
    virtual bool inRegion(int top, int left, int right, int bottom) = 0;
    virtual void step();
    virtual void draw(QPainter *);

    virtual ~BodyWrapper();

private:
    int curr_force_id;

protected:
    b2World *world;
    b2Shape::Type  shape_type;
    b2BodyType body_type;
    b2Vec2 pivot_center;
    float angle_in_radius;
    float density;
    float friction;

    b2Body *body;
    std::map<int, ForceWrapper*> forces;
};

#endif // BODYWRAPPER_H
